﻿using System;
using System.Data;
using visinia.SmartEngine.Providers;
using viBlog.Classes;

namespace viBlog.Providers
{
    public abstract partial class viBlogDataProvider
    {
        #region INIT
        private static viBlogDataProvider _provider;
        private static object _lock = new object();

        public static viBlogDataProvider Provider
        {
            get { InternalInitialize(); return _provider; }
        }
        private static void InternalInitialize()
        {
            if (_provider == null)
            {
                lock (_lock)
                {
                    if (_provider == null)
                    {
                        _provider = (viBlogDataProvider)ProviderController.CreateDataProvider("viBlog");
                        if (_provider == null)
                            throw new Exception("Unable to load default viBlogDataProvider");
                    }
                }
            }
        }
        #endregion

        #region POSTS
        public abstract IDataReader GetPost(int PostId);
        public abstract IDataReader GetPosts();
        public abstract IDataReader GetPostsAdmin();
        public abstract IDataReader GetPostDescriptionAdmin(int PostId);
        public abstract IDataReader GetPostDescription(int PostId);        
        public abstract IDataReader GetPostRelatives(int PostId);        
        public abstract IDataReader AddPost(string Title, string Author, DateTime Date, string Summary, string Url, bool AllowComments, bool IsDraft, string Description);
        public abstract void UpdatePost(int PostId, string Title, string Author, DateTime Date, string Summary, string Url, bool AllowComments, bool IsDraft, string Description);
        public abstract void DeletePost(int PostId);        
        public abstract IDataReader GetPostsByCategory(int CategoryId);
        public abstract IDataReader GetPostsByTag(int TagId);
        public abstract IDataReader GetArchives();
        public abstract IDataReader GetPostsByDate(int Year, int Month);               
        #endregion

        #region CATEGORIES
        public abstract IDataReader GetCategories();
        public abstract IDataReader GetCategories(int PostId);
        public abstract IDataReader GetCategoryPostsCount();
        public abstract void InsertCategory(int CategoryId, int PostId);
        public abstract void RemoveCategory(int CategoryId, int PostId);
        public abstract IDataReader AddCategory(string Category);
        public abstract void UpdateCategory(int CategoryId, string Category);
        public abstract void DeleteCategory(int CategoryId);
        #endregion

        #region TAGS
        public abstract IDataReader GetTags();
        public abstract IDataReader GetTags(int PostId);
        public abstract IDataReader GetTagCount();
        public abstract void InsertTag(int TagId, int PostId);
        public abstract void RemoveTag(int TagId, int PostId);
        public abstract IDataReader AddTag(string name);
        public abstract void DeleteTag(int TagId);
        #endregion

        #region DATAFILTERS
        public abstract IDataReader GetFilters();
        public abstract void AddFilter(int FilterType, int ModuleId, string Data, int ItemsCount);
        public abstract void UpdateFilter(int FilterId, int FilterType, int ModuleId, string Data, int ItemsCount);
        public abstract void DeleteFilter(int FilterId);
        #endregion

        #region BLOG SETTINGS
        public abstract void AddBlogSetting(string key, string value);
        public abstract void UpdateBlogSetting(string key, string value);
        public abstract void DeleteBlogSetting(string key);
        public abstract IDataReader GetBlogSettings();
        #endregion

        #region COMMENTS               
        public abstract IDataReader GetCommentsAdmin();
        public abstract IDataReader GetComment(int CommentId);
        public abstract IDataReader GetComments();
        public abstract IDataReader GetCommentsByPost(int PostId);        
        public abstract void DeleteComment(int CommentId);
        public abstract void DeleteComments(int PostId);
        public abstract IDataReader AddComment(int PostId, string Author, string Email, string Website, DateTime Date, string Content, Comment.CommentStatus Status);
        public abstract IDataReader UpdateComment(int CommentId, int PostId, string Author, string Email, string Website, DateTime Date, string Content, Comment.CommentStatus Status);
        #endregion        
    }
}
